<?php

namespace App\Controller\Admin\Question;

use App\Controller\Admin\BaseController;
use App\Service\Question\QuestionService;
use Hyperf\Di\Annotation\Inject;
use Yj\Apidog\Annotation\ApiController;
use Yj\Apidog\Annotation\FormData;
use Yj\Apidog\Annotation\PostApi;


/**
 * @ApiController(prefix="admin/question/question")
 */
class QuestionController extends BaseController
{
    /**
     * @Inject()
     * @var QuestionService
     */
    protected $questionService;

    /**
     * @PostApi(path="lists")
     * @FormData(key="title",rule="nullable")
     */
    public function lists()
    {
        $params = $this->getValidatorData();
        $data = $this->questionService->lists($params);
        _SUCCESS($data);
    }

    /**
     * @PostApi(path="add")
     * @FormData(key="title",rule="required")
     * @FormData(key="question_detail",rule="required")
     */
    public function add()
    {
        $params = $this->getValidatorData();
        $this->questionService->add($params);
        _SUCCESS();
    }

    /**
     * @PostApi(path="edit")
     * @FormData(key="id",rule="required")
     * @FormData(key="title",rule="required")
     * @FormData(key="question_detail",rule="required")
     */
    public function edit()
    {
        $parmas = $this->getValidatorData();
        $this->questionService->edit($parmas->get('id'), $parmas->except('id'));
        _SUCCESS();
    }

    /**
     * @PostApi(path="del")
     * @FormData(key="id",rule="required")
     */
    public function del(){
        $parmas = $this->getValidatorData();
        $this->questionService->del($parmas->get('id'));
        _SUCCESS();
    }

    /**
     * @PostApi(path="detail")
     * @FormData(key="question_id",rule="required")
     */
    public function detail()
    {
        $questionId = $this->getValidatorData('question_id');
        $data = $this->questionService->detail($questionId);
        _SUCCESS($data);
    }

    /**
     * @PostApi(path="set-field-status")
     * @FormData(key="id")
     * @FormData(key="value")
     * @FormData(key="field")
     */
    public function setFieldtatus()
    {
        $params = $this->getParams(false);
        $this->questionService->setFieldStatus($params->get('id'), $params->get('field'), $params->get('value'));
        _SUCCESS();
    }
}